home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
KlingonBGApp.sit
/
Klingon BG App
/
Source
/
SoundUtils.c
< prev
next >
Wrap
Text File
|
1997-06-28
|
4KB
|
190 lines
// Source code for Klingon Clock. Copyright (C) 1996-1997
// Charles H. Hemstreet IV
//
// Started at MacHack 1996
// Completed at MacHack 1997
//
// Best thanks to:
// My wife Regie, son Chad and baby
// Other thanks to Elden Wood and Bob Clark
//
// This code is distributed "as-is" and implies no warranty or guarantee.
#ifndef __SOUNDUTILS__
#include "SoundUtils.h"
#endif
RoutineDescriptor ExternalCallBackRD =
BUILD_ROUTINE_DESCRIPTOR(uppFilePlayCompletionProcInfo, ExternalCallBack);
pascal void ExternalCallBack (SndChannelPtr theChannel, SndCommand theCommand)
{
long thisA5;
long wasA5;
if (theCommand.param1 == kSoundDone)
{
wasA5 = theCommand.param2;
thisA5 = SetA5(wasA5);
externalPriority = 0;
thisA5 = SetA5(thisA5);
}
}
OSErr openSndChannel(void)
{
OSErr theErr;
#if USESROUTINEDESCRIPTORS
externalCallBackUPP = &ExternalCallBackRD;
#else
externalCallBackUPP = (SndCallBackUPP) &ExternalCallBack;
#endif
theErr = noErr;
if (gChannelOpen)
return theErr;
gSndChannel = 0L;
theErr = SndNewChannel(&gSndChannel, sampledSynth, initNoInterp + initMono,
(SndCallBackUPP)externalCallBackUPP);
if (theErr == noErr)
gChannelOpen = true;
return theErr;
}
OSErr closeSndChannel(void)
{
OSErr theErr;
theErr = noErr;
if (!gChannelOpen)
return theErr;
if (gSndChannel != 0L)
theErr = SndDisposeChannel(gSndChannel, false);
gSndChannel = 0L;
if (theErr == noErr)
gChannelOpen = false;
return theErr;
}
OSErr playASound (short soundID, short priority)
{
SndCommand theCommand;
OSErr theErr;
assert(gSndChannel != nil);
externalPriority = priority;
theCommand.cmd = bufferCmd;
theCommand.param1 = 0;
theCommand.param2 = (long)(gTheSoundData[soundID]);
theErr = SndDoCommand(gSndChannel, &theCommand, false);
return theErr;
}
void doPlayASound (short soundID, short priority)
// Remember! Pass as soundID the sound-number-in-file, NOT the ID!
{
assert(soundID >= 0);
assert(soundID < kNumberSounds);
assert(gChannelOpen != false);
if (priority >= externalPriority)
{
playASound(soundID, priority);
}
}
Boolean SndChanDone(SndChannelPtr chan)
{
/*
Same as SndDone, but you can pass any 'ol sound channel,
not just our private array of snd channels...
*/
OSErr err;
SCStatus status;
// Poll the channel
err = SndChannelStatus(chan, sizeof(SCStatus), &status);
if (err == noErr)
// If the channel is busy, then the sound is NOT done,
// else the sound is done (and the channel is idle)...
return status.scChannelBusy;
else
return err; // Hmm. Error!
} // END SndChanDone
OSErr LoadBufferSounds (void)
{
Handle theSound;
long soundDataSize;
OSErr theErr;
short i;
theErr = noErr;
for (i = 0; i < kNumberSounds; i++)
{
theSound = GetResource('snd ', i + kFirstSoundID);
if (theSound == 0L)
return ResError();
HLock(theSound);
soundDataSize = GetHandleSize(theSound) - 20L;
HUnlock(theSound);
gTheSoundData[i] = NewPtr(soundDataSize);
if (gTheSoundData[i] == 0L)
return ResError();
HLock(theSound);
BlockMove((Ptr)(*theSound + 20L), gTheSoundData[i], soundDataSize);
HUnlock(theSound);
ReleaseResource(theSound);
}
return theErr;
}
void waitCloseChannel(void)
{
EventRecord myEvent;
Boolean theResult;
Boolean channelBusy;
channelBusy = SndChanDone(gSndChannel);
while (channelBusy)
{
theResult = WaitNextEvent(everyEvent, &myEvent, kWaitSeconds, 0L);
switch (theResult)
{
default:
{
channelBusy = SndChanDone(gSndChannel);
}
}
}
closeSndChannel();
}